angular.module('mamApp').controller('playChannelDetailController', ['$scope', 'PlayControlManager', '$state', '$uibModal', 'ChannelManager','ImsDialog','ImsErr',
    function ($scope, PlayControlManager, $state, $uibModal, ChannelManager,ImsDialog, ImsErr) {
        $scope.clientType=$state.params.clientType;
        $scope.search = {
            clientType: $state.params.clientType||'',
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            keyword: $state.params.keyword
        };
        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        }

        $scope.noPermission=false;

        PlayControlManager.playChannelList([$scope.search.clientType,$scope.search.pageNo,$scope.search.pageSize],$scope.search).then(function (result) {
         console.log(result,"kkk");
           if(result.data.c=='n'){
               $scope.noPermission=true;
           }else{
               $scope.noPermission=false;
               $scope.channels = result.data.pageList;
               $scope.paginationConf.totalItems = result.data.total;
           }

        });


        $scope.delete = function (channel) {
            ImsDialog.open({title: "删除渠道", message: "确定删除这条渠道吗？"}).then(function (a) {
                if (a == "ok") {
                    PlayControlManager.playChannelDel([channel.id]).then(function (result) {
                        if (result.data.c == "s") {
                            $state.reload();
                        } else {
                            ImsErr.open({message:"该渠道已被占用"})
                        }
                    })
                }
            })
        };

        $scope.new=function (clientType) {
            $scope.formData={};
            $scope.platformId=clientType;
            var modalInstance = $uibModal.open({
                openedClass:"modal-open-normal",
                animation: true,
                templateUrl: 'newChannel.html',
                controller: 'newChannelModalController',
                resolve: {
                    data: function () {
                        return {platformId:$scope.platformId,formData:$scope.formData};
                    }
                }
            })
            modalInstance.result.then(function (result) {
                $scope.data=result
            })
        };

        $scope.edit=function (channel) {
            var modalInstance = $uibModal.open({
                openedClass:"modal-open-normal",
                animation: true,
                templateUrl: 'editChannel.html',
                controller: 'editChannelModalController',
                resolve: {
                    param:function () {
                        return {channel:channel};
                    }
                }
            })
            modalInstance.result.then(function (result) {
                $scope.data=result
            })
        }
    }])

